define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'spell_order/index' + location.search,
                    add_url: 'spell_order/add',
                    edit_url: 'spell_order/edit',
                    del_url: 'spell_order/del',
                    multi_url: 'spell_order/multi',
                    table: 'spell_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'orderId', title: __('Orderid')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'ptid', title: __('Ptid')},
                        {field: 'fromUid', title: __('Fromuid')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'totalPrice', title: __('Totalprice'), operate:'BETWEEN'},
                        {field: 'balance', title: __('Balance'), operate:'BETWEEN'},
                        {field: 'spellGroup', title: __('Spellgroup')},
                        {field: 'recName', title: __('Recname')},
                        {field: 'recPhone', title: __('Recphone')},
                        {field: 'recAddress', title: __('Recaddress')},
                        {field: 'province', title: __('Province')},
                        {field: 'city', title: __('City')},
                        {field: 'district', title: __('District')},
                        {field: 'spellNum', title: __('Spellnum')},
                        {field: 'isFinished', title: __('Isfinished')},
                        {field: 'finishTime', title: __('Finishtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'isPaid', title: __('Ispaid')},
                        {field: 'payTime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status')},
                        {field: 'type', title: __('Type')},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});